#ifndef AODV_RERR_H
#define AODV_RERR_H

#include "aodv_types.h"
#include "aodv_socket.h"
#include "aodv_routing_table.h"

// RERR类型定义
typedef enum {
    RERR_DEST_UNREACHABLE,  // 目的不可达
    RERR_NODE_UNREACHABLE   // 节点不可达
} rerr_type_t;

// RERR标志位定义
#define RERR_FLAG_NODE_UNREACHABLE 0x00
#define RERR_FLAG_DEST_UNREACHABLE 0x01

// 函数声明 - 使用与aodv_packet.h相同的函数签名
void build_rerr_packet_with_type(aodv_rerr *rerr, uint32_t dest_addr, uint32_t dest_seq_num, rerr_type_t type);
int validate_rerr_message(const aodv_rerr *rerr);
int process_rerr_message(const aodv_rerr *rerr, uint32_t sender_addr, 
                        aodv_routing_table *routing_table, uint32_t local_ip);
int forward_rerr_message(const aodv_rerr *rerr, SOCKET socket, 
                        aodv_routing_table *routing_table, uint32_t local_ip);
int send_rerr_message(uint32_t dest_addr, uint32_t dest_seq_num, 
                     SOCKET socket, aodv_routing_table *routing_table, uint32_t local_ip);
int handle_route_error(uint32_t broken_link_addr, SOCKET socket, 
                      aodv_routing_table *routing_table, uint32_t local_ip);

#endif // AODV_RERR_H